/**
 * @param {string} s
 * @return {string}
 */
var longestPalindrome = function(s) {
    if (s.length === 0) return "";
    let result = s[0];
    let maxLength = result.length;
    let left, right; 

    for(let i=0;i<s.length;i++){
        left=i;
        right=i;

        while(left >= 0 && right < s.length && s[left] === s[right]){
            const currentLength = right - left + 1;
            if(currentLength > maxLength){ 
                result = s.slice(left, right + 1);
                maxLength = currentLength;
            }
            left -= 1;
            right += 1;
        }

        left=i;
        right=i+1;

        while(left >= 0 && right < s.length && s[left] === s[right]){
            const currentLength = right - left + 1;
            if(currentLength > maxLength){
                result = s.slice(left, right + 1);
                maxLength = currentLength;
            }
            left -= 1;
            right += 1;
        }
    }

    return result;
};